package com.iran.order.example;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class Waiter extends Observable {
    private List<Command> orders = new ArrayList<>();

    /**
     * 记录订单
     * @param command
     */
    public void setCommand(Command command) {
        if ("鸡翅哥".equals(command.getCommandName())){
            System.out.println("没有鸡翅了，换个别的呗");
        }else {
            orders.add(command);
            System.out.println("增加了烤肉订单");
        }
    }

    /**
     * 取消命令
     * @param command
     */
    public void cancelOrder(Command command){
        orders.remove(command);
        System.out.println("记录日志取消订单:"+command.toString());
    }
    /**
     * 通知烤肉者
     */
    public void notifyCommand(){
        orders.forEach(d->{
            d.excuteCommand();
        });
    }
}
